package com.fbd.service;

import com.fbd.internalcommon.dto.DirectionResponse;
import com.fbd.internalcommon.dto.ForecastPriceDTO;
import com.fbd.internalcommon.dto.ResponseResult;
import com.fbd.internalcommon.response.ForecastPriceResponse;
import com.fbd.remote.ServiceMapClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ForecastPriceService {
    @Autowired
    private ServiceMapClient serviceMapClient;
    public ResponseResult forecastPrice(ForecastPriceDTO forecastPriceDTO) {


        // 调用地图服务，查询距离和时长
        ResponseResult<DirectionResponse> driving = serviceMapClient.driving(forecastPriceDTO);
        DirectionResponse data = driving.getData();
        Integer distance = data.getDistance();
        Integer duration = data.getDuration();
        double price;
        if (distance/1000 < 2){
            price = 5;
        }else {
            price = (distance - 2000)/1000 * 5 + (duration/60)*0.5;
        }
        ForecastPriceResponse forecastPriceResponse = new ForecastPriceResponse();
        forecastPriceResponse.setPrice(price);

        return ResponseResult.success(forecastPriceResponse);
    }
}
